package com.study.dao;

import com.study.domain.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface CustomerDao extends JpaRepository<Customer,Long> , JpaSpecificationExecutor<Customer> {

    @Query(value = "from Customer where custName = ?")
    public Customer findJpql(String custName);

    @Query(value = "from Customer where custName = ? and custId = ?")
    public Customer findNameAndId(String custName,Long id);

    @Query(value = "update Customer set custName = ? where custId = ?")
    @Modifying
    public void updateCustomer(String custName,Long id);

    //nativeQuery = true 表示使用sql ，false 使用jpql
    //@Query(value = "select * from cst_customer" ,nativeQuery = true)
    @Query(value = "select * from cst_customer where cust_name like ?" ,nativeQuery = true)
    public List<Object[]> findSql(String name);

    /**
     * 方法名的约定：
     *    findBy:查询
     *       对象中的属性名（首字母大写）：查询的条件
     */
    public Customer findByCustName(String custName);

    /**
     * 方法命名查询法之模糊查询
     */
    public List<Customer> findByCustNameLike(String custName);

    /**
     * 多条件查询
     */
    public Customer findByCustNameLikeAndCustInsdustry(String custName,String industry);

}
